<template>
    <div>
        <van-field label="商品名称:" v-model="form.goods_name"></van-field>
        <van-field label="商品个数:" v-model="form.count"></van-field>
        <van-field label="商品价格:" v-model="form.price"></van-field>
        选择订单
        <select name="" id="" v-model="form.order_id">
            <option :value="i.id" v-for="i in list_1" :key="i">{{i.name}}</option>
        </select>
        <van-button @click="addList">添加</van-button>
    </div>
</template>

<script>
    export default {
        data(){
            return{
                form:{},
                list_1:[]
            }
        },
        methods:{
            getList(){
                this.$axios.get('text/ordersM').then(res=>{
                    this.list_1 = res.data.list
                    // 默认显示第一条
                    this.form.order_id = this.list_1[0]['id']
                })
            },
            addList(){
                this.$axios.post('text/ordersM',this.form)
                .then(res=>{
                    if(res.data.code==200){
                        alert('添加成功')
                    }
                })
            }
        },
        mounted(){
            this.getList()
        }
    }
</script>

<style scoped>

</style>